package com.example.foo.member.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.member.model.MemberBankcard;
import com.example.foo.member.query.MemberBankcardQuery;

@org.apache.ibatis.annotations.Mapper
public interface MemberBankcardDao extends com.example.core.dao.BaseDao<MemberBankcard, Long> {

	public default PageResult<MemberBankcard> findMemberBankcards(MemberBankcardQuery memberBankcardQuery, Pageable pageable) {
		QueryWrapper<MemberBankcard> queryWrapper = createQueryWithBaseIf(memberBankcardQuery);
		//
		if (memberBankcardQuery.getType() != null) {
			queryWrapper.eq("type", memberBankcardQuery.getType());
		}
		if (memberBankcardQuery.getState() != null) {
			queryWrapper.eq("state", memberBankcardQuery.getState());
		}
		if (StringUtils.isNotEmpty(memberBankcardQuery.getCardHolder())) {
			queryWrapper.eq("card_holder", memberBankcardQuery.getCardHolder());
		}
		if (StringUtils.isNotEmpty(memberBankcardQuery.getCardNumber())) {
			queryWrapper.like("card_number", memberBankcardQuery.getCardNumber());
		}
		if (StringUtils.isNotEmpty(memberBankcardQuery.getCardCellphone())) {
			queryWrapper.like("card_cellphone", memberBankcardQuery.getCardCellphone());
		}
		if (memberBankcardQuery.getUserId() != null) {
			queryWrapper.eq("user_id", memberBankcardQuery.getUserId());
		}
		return findPages(queryWrapper, pageable);
	}

}
